package cn.bsuc.crm.execption;

import cn.bsuc.crm.util.Code;
import cn.bsuc.crm.util.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author : zhuoyuan
 * @date : 2022/10/8 18:13
 * @description :
 */
@RestControllerAdvice
public class ProjectExceptionAdvice {

    @ExceptionHandler(SystemException.class)
    public Result doSystemException(SystemException ex){
        //记录日志
        //发送消息给运维
        //发送邮件给开发人员,ex对象发送给开发人员
        return Result.fail(ex.getCode(),ex.getMessage());
    }

    @ExceptionHandler(BusinessException.class)
    public Result doBusinessException(BusinessException ex){
        return Result.fail(ex.getCode(),ex.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result doException(Exception ex){
        ex.printStackTrace();
        return Result.fail(Code.SYSTEM_ERR, "嘿嘿，你代码出现了异常，请认真对待。");
    }
}
